using UnityEngine;
using System.Net.NetworkInformation;
using System.Security.Cryptography;

public class GetMacAddress
{

    public static string GetMacAddBase64()
    {
        string physicalAddress = "";
        NetworkInterface[] nice = NetworkInterface.GetAllNetworkInterfaces();
        foreach (NetworkInterface adaper in nice)
        {
            Debug.Log(adaper.Description);
            if (adaper.Description == "en0")
            {
                physicalAddress = adaper.GetPhysicalAddress().ToString();
                break;
            }
            else
            {
                physicalAddress = adaper.GetPhysicalAddress().ToString();
                if (physicalAddress != "")
                {
                    break;
                };
            }
        }
        string base64 = "";
        byte[] myByte = System.Text.Encoding.UTF8.GetBytes(physicalAddress);
        base64 = System.Convert.ToBase64String(myByte);
        return base64;
    }
    public static string GetMacAdd64()
    {
        string physicalAddress = "";
        NetworkInterface[] nice = NetworkInterface.GetAllNetworkInterfaces();
        foreach (NetworkInterface adaper in nice)
        {
            Debug.Log(adaper.Description);
            if (adaper.Description == "en0")
            {
                physicalAddress = adaper.GetPhysicalAddress().ToString();
                break;
            }
            else
            {
                physicalAddress = adaper.GetPhysicalAddress().ToString();
                if (physicalAddress != "")
                {
                    break;
                };
            }
        }
        return physicalAddress;
    }
    public string TurntoBase64(string physicalAddress)
    {
        string base64 = "";
        byte[] myByte = System.Text.Encoding.UTF8.GetBytes(physicalAddress);
        base64 = System.Convert.ToBase64String(myByte);
        return base64;
    }

    public static string GetUniqueIdentifier()
    {
        return SystemInfo.deviceUniqueIdentifier;
    }

    public static string GetUniqueIdentifierMd5()
    {
        string ConvertString = SystemInfo.deviceUniqueIdentifier;
        MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
        string t2 = System.BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(ConvertString)), 4, 8);
        t2 = t2.Replace("-", "");
        return t2;
    }

}
